<?php

namespace App\Http\Controllers;


use EasyWeChat\Factory;
use Illuminate\Http\Request;

class ExampleController extends Controller
{
    public function example()
    {
        return 'example';
    }
    public function get_user()
    {
        $officialAccount = EasyWeChat::officialAccount();
        $app = app('wechat.official_account');
        $app->user->list();
    }
    public function api()
    {
        $app = app('wechat.official_account');


        $app->server->push(function ($message) {
            json_encode($message);
            return "您好！欢迎关注 南秀科技!";
        });

        $response = $app->server->serve();
        return $response;

        $echoStr = $_GET["echostr"];
        if($this->checkSignature()){
            echo $echoStr;
            exit;
        }
    }

    public function addmenu()
    {
        $app = app('wechat.official_account');
        $buttons = [
            [
                "type" => "view",
                "name" => "官网",
                "url"  => "http://nanxiu.net/"
            ],
            [
                "name"       => "我的",
                "sub_button" => [
                    [
                        "type" => "view",
                        "name" => "宜百伴",
                        "url"  => "http://nanxiu.club/banding"
                    ],
                    [
                        "type" => "view",
                        "name" => "个人信息",
                        "url"  => "http://nanxiu.club/info"
                    ],

                ],
            ],
        ];
        $app->menu->create($buttons);
        $response = $app->server->serve();
        return $response;
    }
}
